<?php
/**
 * $Id: installscript.php v 1.00 21 June 2005 John N Exp $
 * Module: WF-Links
 * Version: v1.0.3
 * Release Date: 21 June 2005
 * Developer: John N
 * Team: WF-Projects
 * Licence: GNU
 */

include "../../mainfile.php";

function xoops_module_install_wflinks( $module )
{
	return ( check_wf_resources_types() && check_wf_resources() ) ? true : false;
} 

function xoops_module_update_wflinks( $module )
{
	return ( check_wf_resources_types() && check_wf_resources() ) ? true : false;
} 

function check_wf_resources_types()
{
    global $xoopsDB;
    $table = "wf_resource_types";
    $output = "";

    $test = $xoopsDB -> queryF( "SELECT * FROM '" . $xoopsDB -> prefix( $table ) . "'" );

    if ( !$test )
    {
        $result = $xoopsDB -> queryF( "CREATE TABLE " . $xoopsDB -> prefix( $table )
             . "( rtid int(11) NOT NULL auto_increment,"
             . "name text NOT NULL,"
             . "description text,"
             . "url text,"
             . "resource_list_select text,"
             . "module_id int(11) default NULL,"
             . "PRIMARY KEY  (rtid)"
             . ") COMMENT = 'WF : resource types'" );

        if ( !$result )
        {
            $out = 0; 
            // $output[] = "-------------------------------------------------</br>";
            // $output[] = "<b>Error:</b> Could <span style='color:#ff0000;font-weight:bold'>not create</span> new table <b>$table</b>!</br>";
            // $output[] = "<b>OR:</b> table  <b>$table</b> <span style='color:#ff0000;font-weight:bold'>already exists </span> !</br>";
            // $output[] = "-------------------------------------------------</br>";
        } 
        else
        {
            $out = 1; 
            // $output[] = "<b>Success:</b> Table <b>$table</b> was <span style='color:#FF0000;font-weight:bold'>created</span> Successfully</br>";
            $insert = $xoopsDB -> queryF( "INSERT INTO xoops_wf_resource_types VALUES (1, 'URL', 'URL resource.  Use it to reference generic URL resources', NULL, NULL, NULL)" );
            $insert = $xoopsDB -> queryF( "INSERT INTO xoops_wf_resource_types VALUES (2, 'Forum', 'Link to existing discussion forum', '/modules/newbb/viewforum.php?forum=', 'SELECT forum_id, forum_name FROM `xoops_bb_forums` ORDER BY forum_name', 7)" );
            $insert = $xoopsDB -> queryF( "INSERT INTO xoops_wf_resource_types VALUES (3, 'News', 'Links to existing News Topics', '/modules/news/index.php?storytopic=', 'select topic_id, topic_title from xoops_topics', 2)" );
            $insert = $xoopsDB -> queryF( "INSERT INTO xoops_wf_resource_types VALUES (4, 'FAQ', 'Links to FAQ categories', '/modules/wffaq/index.php?op=cat&catID=', 'SELECT catID, name FROM xoops_wffaq_categories', 6)" );
            if ( !$insert )
            {
                $out = 0; 
                // $output[] = "-------------------------------------------------";
                // $output[] = "<b>Error:</b> Could <span style='color:#ff0000;font-weight:bold'>not insert data </span> in table <b>$table</b>!</br>";
                // $output[] = "-------------------------------------------------";
            } 
            else
            {
                $out = 1; 
                // $output[] = "<b>Success:</b> <b>$table</b> : new data <span style='color:#FF0000;font-weight:bold'>inserted</span> Successfully</br>";
            } 
        } 
    } 
    else
    {
        $out = 1; 
        // $output[] = "<b>Notice:</b> Table <b>$table</b> already <span style='color:#FF0000;font-weight:bold'>exists</span> in the database</br>";
    } 
    return $out;
} 

function check_wf_resources()
{
    global $xoopsDB;
    $table = "wf_resources";
    $output = "";
    $test = $xoopsDB -> queryF( "SELECT * FROM '" . $xoopsDB -> prefix( $table ) . "'" );

    if ( !$test )
    {
        $result = $xoopsDB -> queryF( "CREATE TABLE " . $xoopsDB -> prefix( $table )
             . "(rid int(10) unsigned NOT NULL auto_increment,"
             . "lid int(10) unsigned NOT NULL default '0',"
             . "rtid smallint(5) unsigned NOT NULL default '0',"
             . "mid smallint(5) unsigned NOT NULL default '0',"
             . "name text NOT NULL,"
             . "description text,"
             . "url text,"
             . "item_id int(10) unsigned default NULL,"
             . "PRIMARY KEY  (rid)"
             . ") COMMENT = 'WF : resources'" );

        if ( !$result )
        {
            $out = 0; 
            // $output[] = "-------------------------------------------------</br>";
            // $output[] = "<b>Error:</b> Could <span style='color:#ff0000;font-weight:bold'>not create</span> new table <b>$table</b>!</br>";
            // $output[] = "<b>OR:</b> table  <b>$table</b> <span style='color:#ff0000;font-weight:bold'>already exists </span> !</br>";
            // $output[] = "-------------------------------------------------</br>";
        } 
        else
        {
            $out = 1; 
            // $output[] = "<b>Success:</b> Table <b>$table</b> was <span style='color:#FF0000;font-weight:bold'>created</span> Successfully</br>";
        } 
    } 
    else
    {
        $out = 1; 
        // $output[] = "<b>Notice:</b> Table <b>$table</b> already <span style='color:#FF0000;font-weight:bold'>exists</span> in the database</br>";
    } 
    return $out;
} 

?>